﻿using LcAudit.BPM.Core.Model;
using LcAudit.Common.Data;
using LcAudit.Common.Data.SqlServer;
using LcAudit.Common.Provider;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LcAudit.BPM.Core.Dal
{
    public partial class bidderinfoDal : BaseRepository<bidderinfo>
    {

        public static bidderinfoDal Instance
        {
            get { return SingletonProvider<bidderinfoDal>.Instance; }
        }
        public int AddBidderTo(int bagid, params int[] bidders)
        {
            string sql = "insert into bagbidder (bagid,bid) values({0},{1})";
            StringBuilder sb = new StringBuilder();
            foreach (var rid in bidders)
            {
                if (SqlEasy.ExecuteScalar(string.Format("select count(*) from bagbidder where bagid={0} and bid={1}",bagid,rid)).ToString() == "0")
                {
                    sb.AppendFormat(sql, bagid, rid);
                    sb.AppendLine();
                }
            }
            if (!string.IsNullOrEmpty(sb.ToString()))
            {
                return SqlEasy.ExecuteNonQuery(sb.ToString());
            }
            return 0;
        }

    }
}
